import React, { Component } from 'react'
import { getUserInfo } from '../../data/api'
import { withRouter } from 'react-router-dom'
import { TabBar, Card, Button, Modal ,Toast} from 'antd-mobile'
import avatar from '../../upload/avatar.png'
const alert = Modal.alert;
export class MyNoLogin extends Component {
    constructor(props) {
        super(props)

        this.state = {

        }
    }
    conpm
    componentWillMount() {
        // 获取用户信息
        getUserInfo().then(res => {
            const { meta: { status }, message } = res
            if (status === 200) {
                this.setState({
                    phone: message.user_tel
                })
            }
        })
       
    }

    componentDidMount(){
        sessionStorage.getItem("token")
    }
    // 退出
    logout = () => {
        alert('即将退出账号', '您确定吗?', [
            {
                text: '我还没逛完', 
                style: {
                    backgroundColor: '#777',
                    color: '#fff',
                    fontWeight: 700
                }
            },
            {
                text: '确定', 
                style: {
                    backgroundColor: 'rgb(244, 51, 60)',
                    color: '#fff',
                    fontWeight: 700
                }, 
               
                onPress: () => {
                    // 退出
                    // this.props.loginOut()
                    // // 清除cartReducer中的数据
                    // this.props.token()
                    // this.props.history.push('/mynologin')
                    sessionStorage.clear()
                    Toast.info('退出成功',1,()=>{
                        this.props.history.push("/myLoginB")
                       })
                }
            }
        ])
    }
  

    render() {
        return (
            <div>
                <Card>
                    <Card.Header
                        title="暴走"
                        thumb={avatar}
                        thumbStyle={{ width: 43 }}
                        style={{ fontSize: 15 }}
                        extra={<span style={{ fontSize: 13 }}>{this.state.phone}</span>}
                    />
                    <Card.Header
                        title="我的订单"
                        style={{ fontSize: 15 }}
                    />
                </Card>
                <TabBar
                    unselectedTintColor="#949494"
                    tintColor="#33A3F4"
                    barTintColor="white"
                >
                    <TabBar.Item
                        title="所有订单"
                        key="Home"
                        icon={<i className="iconfont icon-dingdan_huaban"></i>}
                        onPress={() => { this.props.history.push('/orderList/0') }}
                    >
                    </TabBar.Item>
                    <TabBar.Item
                        title="待付款"
                        key="obligation"
                        icon={<i className="iconfont icon-daifukuan"></i>}
                        onPress={() => { this.props.history.push('/orderList/1') }}
                    >
                    </TabBar.Item>
                    <TabBar.Item
                        title="待发货"
                        key="Mine"
                        icon={<i className="iconfont icon-daifahuo1"></i>}
                        onPress={() => { this.props.history.push('/orderList/2') }}
                    >
                    </TabBar.Item>
                </TabBar>
                <Button onClick={this.logout}>退出登录</Button>
            </div>
        )
    }
}

export default withRouter(MyNoLogin)
